<template>
  <div>
    <!-- 导航栏 -->
    <van-nav-bar
      :title="titletop"
      left-arrow
      :border="false"
      fixed
      class="bg-primary color-white"
      @click-left="$utils.back($route.path)"
    />
    <div class="has-top">
    <div class="wrapperbg bg-primary"></div>
    <div class="wrapper">
      <!-- <div class="ontitle fs-32">基础信息</div> -->
      <div class="register-form">
        <van-cell-group>
          <van-field
           @click="setUser"
            v-model="model.RealName"
            readonly
            required
            clickable
            label="客户名称"
            placeholder="请选择客户"
          />
          <van-field clearable v-model="model.grade" label="报价等级"  v-if="behalf==0">
            <template #input>
              <div class="gradeList">
                <div :class="gradeActive==index?'active':''" v-for="(item,index) in gradeList" :key="index" @click="selectGrad(item,index)">{{item.Name}}</div>
              </div>
            </template>
          </van-field>
          <van-field clearable v-model="model.delivery" label="配送方式" required>
            <template #input>
              <van-radio-group v-model="radio" v-for="(item,index) in offerlist" :key="index">
                <van-radio :name="index" checked-color="#eb1010" class="mr-40" @click="changeRadio(index)">{{ item.value }}</van-radio>
              </van-radio-group>
            </template>
          </van-field>
          <div v-if="radio==0 && model.RealName">
            <div class="addressDiv pos-r"  @click="goAddress()" v-if="address.Address || address.ContactAddress">
              <img class="mapicon" src="@/assets/images/mapicon.png" />
              <div>
                <div class="fs-28 fw-b">{{ address.ProvinceName }}{{ address.CityName }}{{ address.AreaName }}{{ address.StreetName }}{{ address.ContactAddress }}</div>
                <div>{{address.ContactName}} {{address.ContactTel}}</div>
              </div>
              <svg-icon icon-class="right" class="fs-22 righticon" @goPage="goAddress()"/>
            </div>
            <div class="addressDiv" @click="goAddress()" v-else>
              <div>请先添加收货地址</div>
            </div>
          <div  v-if="radio==0" style="height: 12px;"></div>
          </div>
      </van-cell-group>
      </div>
      <div class="ontitle fs-32"><div>商品清单</div><div @click="getadd(0)" class="addproduct"><svg-icon icon-class="add" class="fs-26 color3" @goPage="getadd(0)" /><div>添加商品</div></div></div>
      <div class="pd-24 bg-white mb-20" v-if="cartList.length > 0">
          <van-checkbox-group v-model="checkedList">
            <div class="flex flex-s-c checkAll" v-if="editState">
              <div class="flex flex-center">
                <p class="checkbox fs-28" :class="checkAllState?'checked':''" @click="checkAll">全选</p>
                <p class="one-del" @click="delProduct">删除</p>
              </div>
              <p class="submitBtn fs-28" @click="editNO">退出编辑</p>
            </div>
            <div class="flex flex-s-c" v-else>
              <div class="flex flex-center">
                <p class="fs-28">共{{cartList.length}}件</p>
              </div>
              <!-- <p class="submitBtn fs-28" @click="getadd(1)">编辑</p> -->
            </div>
            <div class="flex product" v-for="(item,index) in cartList"  :key="index">
              <div class="w-50 flex pr-25" v-if="editState"><van-checkbox :name="item.ID" checked-color="#F1270C" @click="checkEdit(item)" /></div>
              <div class="flex ptb-30" style="width: 100%;">
                <img-box class="is-160 br-10 flex-s-0" :img-url="item.V_ThumbnailUrl410" />
                <div class="productItem-detail ml-20 flex-1">
                  <p class="text-show-line-2 mb-10 color-dark fs-28">{{ item.V_Title }}</p>
                  <!-- <p class="fs-28 color-gray-light">货号：ZG-NSSB52-1</p> -->
                  <p class="fs-28 color-gray-light">规格：{{item.V_AttributeNameValue?item.V_AttributeNameValue.slice(0, -1):'默认规格'}}</p>
                  <div class="flex-s-s fs-28" style="color: #666;">
                    <div>成本价：¥{{parseFloat(Number(item.CostPrice * item.Ratio).toFixed(2))}}</div>
                    <div>售价：¥{{ parseFloat(Number(item.V_SalePrice * item.Ratio).toFixed(2)) }} / {{
								item.RatioUnit }}</div>
                  </div>
                  <div class="flex-s-s mt-10 fs-28">
                    <p class="" v-if="behalf==0">
                    客户价￥<input class="numinput mr-10" type="number" v-model.number="item.editmoney" @blur="changePrice(item)">
                    </p>
                    <div v-else class="color-primary fs-32 fw-b">￥{{item.editmoney}}</div>
                    <div class="flex-fe-c flex-s-0 ml-0">
                      <svg-icon icon-class="delete-3" class="color-primary fs-42 " :class="item.Amount <= 0 ? 'opacity-1' : ''"
                        @goPage="changeAmount(item, item.Amount, item.Stock, -1, item.MinimumOrder, item.AddNum,index)" />
                      <div class="btn-input-box1">
                        <!-- <input v-model="item.Amount" type="number" class="btn-input"
                          @blur="changeAmount(item, item.Amount, item.Stock, 0, item.MinimumOrder, item.AddNum)"> -->
                          <div class="flex fs-32 pl-20 pr-20 inputmax" @click="editPrice(item)">{{item.Amount}}</div>
                      </div>
                      <svg-icon icon-class="add-1" class="color-primary fs-42"
                        :class="(item.Amount >= item.Stock && switch7 !== 1) ? 'opacity-1' : ''"
                        @goPage="changeAmount(item, item.Amount, item.Stock, 1, item.MinimumOrder, item.AddNum)" />
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </van-checkbox-group>
      </div>
      <div class="pd-24 bg-white mb-100 fs-28" v-if="cartList.length > 0">
        <div class="flex-s-s ptb-10" >
          <div>数量合计</div>
          <div class="fw-b">{{totalAmount}}</div>
        </div>
        <div class="flex-s-s ptb-10">
          <div>合计金额</div>
          <div class="fw-b">¥{{totalMoney}}</div>
        </div>
        <div class="flex-s-s ptb-10">
          <div>合计运费</div>
          <div class="fw-b">¥{{PostageMoney}}  <span v-if="behalf==0" @click="editPostag"><svg-icon icon-class="edit" class="fs-22" @goPage="editPostag"/></span></div>
        </div>
        <div style="height: 1px;background: #F0F0F0;"></div>
        <div class="ptb-20" style="text-align: right">合计金额：<span style="color: #EC612A;">¥</span><span class="fs-36 fw-b" style="color: #EC612A;">{{totalTotal}}</span></div>
      </div>
      <div class="bt-button flex-s-s">
        <van-button type="danger" class="bor-ra1 border-primary color-primary" size="large" v-if="behalf==0" @click="submit">保存报价</van-button>
        <van-button type="danger" class="bor-ra  bg-primary" size="large" @click="createOrder">生成订单</van-button>
      </div>
    </div>
    </div>
    <van-dialog v-model="auditShow" title="修改运费" show-cancel-button closeable cancel-button-text="取消" confirm-button-text="确定" close-on-click-overlay @confirm="handleconfirm" @cancel="handleclose">
				<van-field v-model="PostageMoneytemp" label="运费" type="input" class="fs-32 mt-15 fw-b" placeholder="修改运费" />
	  </van-dialog>
    <van-dialog v-model="editPricediv" title="请输入订购数量" show-cancel-button closeable cancel-button-text="取消" confirm-button-text="确定" close-on-click-overlay @confirm="editPriceconfirm">
        <div style="text-align: center;" class="pt-50 pb-50">
				  <input v-model="Amounttemp" type="number" class="fs-32 fw-b amouninput" />
        </div>
	  </van-dialog>
    <van-popup v-model="addressShow" position="bottom" class="bottom-popup">
			<addressList class=" bg-gray" :userId="model.UserId" style="min-height:100vh" @colseAdress="closePopup" @changeAddress="changeAddress" />
		</van-popup>
  </div>
</template>

<script>
import SIdentify from 'components/sIdentify'
import amapSelect from 'components/amapSelect'
import areaList from 'utils/area'
import { upLoad } from 'api/upload'
import { getStoreCategoryTreeList } from 'api/storeCategory'
import { storeApply } from 'api/store'
import imgBox from 'components/imgBox'
import { GetWholeSaleListForSku,GetProductDataBySubmit,SaveUserProductByEmployee,AddOrEditUserCarList,AddOrUpdateAmount,GetUserCarList,GetUserSendStore,StatisPostageMoneyByPayProductTemp} from 'api/product'
import { GetMemberGradeList,GetUserAddressList} from 'api/member'
import { SubmitFromStoreMemberCar} from 'api/order'
import { GetBusinessFunction } from 'api/businessSetting'
import addressList from 'components/address'
export default {
  components: {
    SIdentify,
    amapSelect,
    imgBox,
    addressList
  },
  props: {
    clientWidth: {
      type: Number,
      default: document.body.clientWidth
    }
  },
  computed: {
    numTotal() {
      let Arr = 0
      this.productList.forEach((item,index) => {
        Arr = Arr+Number(item.Amout)
      })
      return Arr
    },
    priceTotal() {
      let Arr = 0
      this.productList.forEach((item,index) => {
        Arr = Arr+(Number(item.Amout)*item.userPrice)
      })
      return Arr
    },
    totalTotal() {
      return (Number(`${this.totalMoney}`)+Number(`${this.PostageMoney}`)).toFixed(2)
    },
  },
  data() {
    return {
      titletop:'新增报价单',
      offerlist:[
				{
					id:0,
					value:'物流配送',
				},
				{
					id:3,
					value:'客户自提',
				},
			],
      radio: 0,
      avar: [],
      advertPictures: [],
      shopPictures: [],
      model: {
      },
			checkedList: [],
      productNameList:[],
      startTime: false,
      endTime: false,
      showArea: false,
      areaList: areaList,
      showAmap: false,
      initAmap: false,
      showBussinessType: false,
      productList:[],
      cartList:[],
      checkAllState: false,
      productIds:'',
      productIdsArr:[],
      // 请求参数
			requestData: {
				ProductType: 1,
				OrderBy: 'AddTime',
				sort: 'desc',
				PageIndex: 1,
				PageSize: 99
			},
      totalAmout:0,
      editState:false,
      gradeActive:-1,
      gradeID:0,
      gradeList:[
        {id:0,name:"8级"},
        {id:1,name:"10级"},
        {id:2,name:"12级"}
      ],
      addressList:[],
      address:{},
			storeId: 0,
      totalMoney: 0,
			totalAmount: 0,
      switch7:0,
			cartRequestList: [],
      PostageMoney:0,
      PostageMoneytemp:0,
      auditShow:false,
      behalf:0,
      Amounttemp:0,
      editPricedivitem:{},
      editPricediv:false,
      addressShow:false
      
    }
  },

  created() {
    this.GetMemberGradeList();
  },
  mounted() {
    if(this.$route.query.behalf){
		  this.behalf = 1
      this.titletop = "代客下单"
		}
    if(localStorage.getItem('customerUser')){
      this.model = JSON.parse(localStorage.getItem('customerUser'));
    }
    if(localStorage.getItem('gradeID')){
      this.gradeID = localStorage.getItem('gradeID');
    }
    if(localStorage.getItem('customerProductList')){
      this.productIdsArr = JSON.parse(localStorage.getItem('customerProductList'));
      this.productIds = JSON.parse(localStorage.getItem('customerProductList')).join(',');
      if( this.productIds.length > 0){
        this.GetWholeSaleListForSku()
      }
    }
    this.GetUserAddressList() 
    this.GetBusinessFunction()
		this.GetUserSendStore()
  },
  methods: {
    GetUserSendStore() {
			GetUserSendStore().then(res => {
				if (res.Data >= 0) {
					this.storeId = res.Data
          if(this.model.UserId){
            this.GetUserCarList()
          }
				}else{
					if(this.model.UserId){
            this.GetUserCarList()
          }
        }
			})
		},
		GetBusinessFunction() {
			GetBusinessFunction(203).then(res => {
				if (res) {
					this.switch203 = res.Data[0].Value;
				}
			})
			GetBusinessFunction(85).then(res => {
				if (res) {
					this.switch85 = res.Data[0].Value;
				}
			})
			GetBusinessFunction(7).then(res => {
				if (res) {
					this.switch7 = res.Data[0].Value;
				}
			})
		},
    changeAmount(item, num, stock, type, MinimumOrder, AddNum,index) {
			console.log(item, "0604")
			const _oldAmount = item.Amount
      
			this.$utils.changeAmount(item, num, stock, type, MinimumOrder, 1, item.oLimitBuy, this.switch7, AddNum)
			if (_oldAmount !== item.Amount || type === 0) {
				const _obj = {}
				_obj.ProductId = item.ProductId
				_obj.Amount = item.Amount
				_obj.SkuId = item.SkuId
				_obj.Ratio = item.Ratio
				_obj.RatioUnit = item.RatioUnit
				if (this.shoplist == 1) {
					_obj.Source = 1
				}
				if (this.storeId || this.storeId === '0') {
					_obj.StoreId = this.storeId
				}
				this.cartRequestList = []
				this.cartRequestList.push(_obj)
			}
      if(item.Amount==0){
				this.AddOrUpdateAmount(item.Amount)
      }
			item.TotalMoney = (item.Amount * item.V_GradePrice * item.Ratio).toFixed(2)
			this.totalMoney = this.getTotalMoney()
			this.totalAmount = this.getTotalAmount()
      this.StatisPostageMoneyByPayProductTemp(1)
		},
    changePrice(item){
      if(item.editmoney < item.V_FactPrice*item.Ratio){
        item.editmoney = item.V_FactPrice*item.Ratio
        this.$toast("不能小于成本价");
      }else{
        item.V_GradePrice =  item.editmoney/item.Ratio
        item.price = item.V_GradePrice
      }
      console.log(this.cartList)
      this.$forceUpdate()
      this.totalMoney = this.getTotalMoney()
			this.totalAmount = this.getTotalAmount()
    },
    editPrice(item){
      console.log(1)
      this.editPricedivitem = item;
      this.Amounttemp = item.Amount
      this.editPricediv = true;
    },
    editPriceconfirm(){
      if(this.Amounttemp > 0){
        this.editPricedivitem.Amount = this.Amounttemp;
        let item = this.editPricedivitem;
        this.changeAmount(item, item.Amount, item.Stock, 0, item.MinimumOrder, item.AddNum);
        this.editPricediv = false;
      }
    },
    		// 计算总额
		getTotalMoney() {
			let totalMoney = 0
			this.cartList.forEach(item => {
				totalMoney += (+item.V_GradePrice * item.Ratio)*item.Amount
			})
      console.log(222222222)
      console.log(totalMoney)
			return totalMoney.toFixed(2)
		},

		// 计算总数量
		getTotalAmount() {
			let totalAmount = 0
			this.cartList.forEach(item => {
				totalAmount += parseInt(item.Amount)
			})
			return totalAmount
		},
    //修改运费弹窗
    editPostag(){
      this.PostageMoneytemp = this.PostageMoney
      this.auditShow = true;
    },
    handleconfirm(){
      if(this.PostageMoneytemp > 0){
        this.PostageMoney = this.PostageMoneytemp
      }
      this.auditShow = false;
    },
    handleclose(){
      this.auditShow = false;
    },
    		// 更新购物车
		AddOrUpdateAmount(amount) {
			if (this.storeId) {
				let param = {}
				param.list = this.cartRequestList
				AddOrEditUserCarList(param).then(res => {
					if (res) {
						console.log(res)
						// this.showList = false
						let _update = false
						if (amount === 0) {
							_update = true
						}
						this.GetUserCarList()

					}
				})
			} else {
				AddOrUpdateAmount(this.cartRequestList).then(res => {
					if (res) {
						// this.showList = false
						let _update = false
						if (amount === 0) {
							_update = true
						}
						this.GetUserCarList()
					}
				})
			}

		},
		// 获取购物车列表
		GetUserCarList() {
      let param = {
        priceType:1,
        storeId:this.storeId,
        ValetUserId:this.model.UserId
      }
      if(localStorage.getItem('gradeID')){
        param.PriceGradeId = +localStorage.getItem('gradeID')
      }
			GetUserCarList(param).then(res => {
				if (res) {
					this.cartList = res.Data;
          this.cartList.forEach(item =>{
            item.editmoney = parseFloat(Number(item.V_GradePrice * item.Ratio).toFixed(2));
            item.price = item.V_GradePrice
          })
          this.totalMoney = this.getTotalMoney()
          this.totalAmount = this.getTotalAmount()
          if(res.Data.length > 0 && this.radio==0){
            this.StatisPostageMoneyByPayProductTemp()
          }
				}
			})
		},
    StatisPostageMoneyByPayProductTemp(num){
      let carIds = '';
      this.cartList.forEach(item =>{
        carIds += item.ID+','
      })
      let param = {
        isTempCar:true
      };
      param.carIds = carIds;
      param.province_id = this.address.ProvinceId
      param.city_id = this.address.CityId
      param.area_id  = this.address.AreaId
      if(num==1){
        param.changePriceList =  this.cartList
      }
      StatisPostageMoneyByPayProductTemp(param).then(res => {
     if (res) {
            this.PostageMoney = res.Data.Value
        }
      })
    },
    GetMemberGradeList(){
      GetMemberGradeList().then(res => {
     if (res) {
          this.gradeList = res.Data;
          if(localStorage.getItem('gradeID')){
          let active = localStorage.getItem('gradeID');
          this.gradeList.forEach((item,index) =>{
            if(active == item.ID){
              this.gradeActive = index
            }
          })
          }
        }
      })
    },
    // 获取收货地址
    GetUserAddressList() {
      GetUserAddressList({userId:this.model.UserId}).then(res => {
        if (res) {
          console.log(res)
          let address = JSON.parse(localStorage.getItem('address'))
          this.addressList = res.Data
          if(res.Data.length==1){
            this.address = res.Data[0]
            // localStorage.setItem('address', JSON.stringify(this.address));
          }
          if(res.Data.length >1){
            this.addressList.forEach(item => {
            if(item.IsDefault){
              this.address = item
              // localStorage.setItem('address', JSON.stringify(this.address));
            }
            })
            // if(this.model.UserId == res.Data[0].UserId){
            //   if(address){
            //     this.address = address
            //   }
            // }
          }
        }
      })
    },
    GetUserAddressList1() {
      GetUserAddressList({userId:this.model.UserId}).then(res => {
        if (res) {
          console.log(res)
          this.addressList = res.Data;
          if(this.addressList.length==0){
            this.address = {}
          }else{
            var filterItem = this.addressList.filter((item) => {
                return item.ID ==  this.address.ID
            })
            console.log(123)
            console.log(filterItem)
            if(filterItem.length==0){
            console.log(333333)
              this.address = {}
            }
          }
        }
      })
    },
    selectGrad(item,index) {
      if(!this.model.RealName){
        this.$toast('请先选择客户')
        return
      }
      if(this.gradeActive==index){
        this.gradeActive = -1;
        this.gradeID = 0
      }else{
        this.gradeActive = index;
        this.gradeID = item.ID
      }
      localStorage.setItem('gradeID', this.gradeID);
      this.GetUserCarList()
    },
    goAddress(){
      // this.$router.push({
      //   path: '/user/address?select=1&userId='+this.model.UserId 
      // })
      this.addressShow = true
    },
    closePopup() {
			this.addressShow = false
      this.GetUserAddressList1()
		},
    changeAddress(address) {
			// 更改地址
      console.log(2222222)
      console.log(address)
			this.address = address
			this.addressShow = false
		},
    changeRadio(index) {
      console.log(index)
      this.radio = index
      this.couponValue = this.offerlist[index].value;
      if(this.radio==1){
        this.PostageMoney = 0
      }
    },
    //删除
    delProduct(){
      console.log(this.checkedList)
      console.log(this.productNameList)
      this.checkedList.forEach(item => {
        this.productList.forEach((subitem,index) => {
          if(item == subitem.ID){
            this.productList.splice(index, 1);
          }
        })
      })
      this.setEditCheck(false)
      let ids = []
      this.productList.forEach((item,index) => {

        ids.push(item.ID)
      })
      if(this.productList.length==0){
        this.editState = false
      }
      localStorage.setItem('customerProductList', JSON.stringify(ids));
      this.$forceUpdate()
    },
    	// 全选、全不选
      checkAll() {
			this.checkAllState = !this.checkAllState
      this.setEditCheck(this.checkAllState)
      this.$forceUpdate()
    },
		// 设置全选、全不选（编辑）
		setEditCheck(bol) {
      const _this = this
      _this.editIds = ''
			this.checkedList = []
			this.productNameList = []
      if (_this.productList && _this.productList.length > 0) {
        _this.productList.forEach(item => {
          item.check = bol
					if(bol){
						_this.editIds += (item.ID + ',')
						this.checkedList.push(item.ID)
						this.productNameList.push(item.ID)
					}
        })
      }
			console.log(bol,_this.editIds,"是实时")
    },
    checkEdit(item){		
			if(this.productNameList.indexOf(item.ID) === -1){
				this.productNameList.push(item.ID)
			}else{
				this.productNameList.splice(this.productNameList.indexOf(item.ID),1)
			}
      if(this.productNameList.length == this.productList.length){
			  this.checkAllState = true
        this.setEditCheck(true)
      }else{
			  this.checkAllState = false
      }
		}, 
    editNO(){
     this.editState = !this.editState 
    },
    setUser(){
      if(this.behalf==1){
        this.$router.push({
          path: '/customerList?behalf='+1 +"&quotation=1"
        })
      }else{
        this.$router.push({
          path: '/customerList?quotation=1' 
        })
      }
   
    },
    getadd(edit){
      if(!this.model.RealName){
        this.$toast('请先选择客户')
        return
      }
      //  if(this.gradeID==0 && this.behalf==0){
      //   this.$toast('请选择报价等级')
      //   return
      // }
      if(this.behalf==1){
        if(edit==1){
          this.$router.push({ path: '/quickPlaceOrder?Guestplace='+1+'&behalf='+1+"&edit=1" });
        }else{
          this.$router.push({ path: '/quickPlaceOrder?Guestplace='+1+'&behalf='+1 });
        }
      }else{
        if(edit==1){
          this.$router.push({
            path: '/quickPlaceOrder?Guestplace='+1+"&PriceGradeId="+this.gradeID+"&ValetUserId="+this.model.UserId+'&edit=1'
          })
        }else{
          this.$router.push({
            path: '/quickPlaceOrder?Guestplace='+1+"&PriceGradeId="+this.gradeID+"&ValetUserId="+this.model.UserId
          })
        }

      }

    },
    // 获取商品列表
		GetWholeSaleListForSku() {
			// this.requestData.storeId = this.storeId
			const _this = this
      _this.requestData.OrderUserId = this.model.UserId
			_this.requestData.skuIds = this.productIds
			
			GetWholeSaleListForSku(_this.requestData).then(res => {
				if (res) {
					if (res.Data.Data.length && res.Data.Data.length > 0) {
						_this.totalAmout = res.Data.RecordAmout;
            let productList =  res.Data.Data;
            productList.forEach(item => {
              item.ProductSkuList.forEach(subitem =>{
                subitem.userPrice = subitem.V_GradePrice
                subitem.ProductName = item.ProductName
                subitem.ThumbnailUrl410 = item.ThumbnailUrl410
                subitem.Amout = 1
                if(_this.productIdsArr.indexOf(subitem.ID) != -1){
                  _this.productList.push(subitem)
                }
              })
            })
					}
				}
			})
		},
    makeCode(o, l) {
      for (let i = 0; i < l; i++) {
        this.identify.identifyCode += this.identify.identifyCodes[this.randomNum(0, this.identify.identifyCodes.length)]
      }
    },
    // 验证码部分end
    // 保存地图详细地址
    confirmAmap(dataModel) {
      // console.log(this.model);
    },
    onConfirm(item) {
      this.model.bussinessType.value = item.text
      this.model.bussinessType.id = item.value
      this.showBussinessType = false
    },

    goto(){
      window.location.href = this.$LocalDomain + '/m/user/StoreManager'
    },
    createOrder(){
      if(!this.model.RealName){
        this.$toast('请先选择客户')
        return
      }
      // if(this.gradeID==0 && this.behalf==0){
      //   this.$toast('请选择报价等级')
      //   return
      // }
      if(this.cartList.length==0){
        this.$toast('请添加商品')
        return
      }
      if(!this.address.ContactName){
        this.$toast('请先添加收货地址')
        return
      }
      
      // localStorage.setItem('postType', JSON.stringify(this.address));
      localStorage.setItem('postType',this.radio);
      localStorage.setItem('postagePrice',this.PostageMoney);
      localStorage.setItem('changePriceList', JSON.stringify(this.cartList));
      localStorage.setItem('address', JSON.stringify(this.address));
      
      let param = {
        UserList:[this.model.UserId]
      }
      let skuList = []
      this.cartList.forEach(item => {
        let obj = {
          productId:item.ProductId,
          id:item.ID,
          salePrice:item.V_GradePrice,
          userPrice:item.editmoney/item.Ratio
        } 
        skuList.push(obj)
      })

      param.skuList = skuList;
      console.log(param)
      SaveUserProductByEmployee(param).then(res => {
				if (res.Data) {
          this.$router.push({
            path: '/customerSubmitOrder' 
          })
				}else{
          this.$toast(res.Msg)
        }
			})
  
      // let carIds = '';
      // this.cartList.forEach(item =>{
      //   carIds += item.ID+','
      // })
      // let param = {
      //     carIds: carIds,
      //     changePriceList: this.cartList,
      //     postType: this.radio,
      //     fromType: 4,
      //     addressId: this.address.ID,
      //     userId: this.model.UserId,
      //     remark: '',
      //     isTempCar: true,
      //     postagePrice:+this.PostageMoney,
          
      // }
      // if(this.storeId > 0){
      //   param.storeId = this.storeId
      // }
      // SubmitFromStoreMemberCar(param).then(res => {
			// 	if (res.Data) {
			// 	}else{
      //     this.$toast(res.Msg)
      //   }
			// })
    },
    submit() {
      const self = this
      if(this.editState){
        this.$toast('请先退出编辑再保存')
        return
      }
      if(!this.model.RealName){
        this.$toast('请选择客户')
        return
      }
      // if(this.gradeID==0 && this.behalf==0){
      //   this.$toast('请选择报价等级')
      //   return
      // }
      if(this.cartList.length==0){
        this.$toast('请添加商品')
        return
      }

      let param = {
        UserList:[this.model.UserId]
      }
      let skuList = []
      this.cartList.forEach(item => {
        let obj = {
          productId:item.ProductId,
          id:item.ID,
          salePrice:item.V_GradePrice,
          userPrice:item.editmoney/item.Ratio
        } 
        skuList.push(obj)
      })

      param.skuList = skuList;
      console.log(param)
      SaveUserProductByEmployee(param).then(res => {
				if (res.Data) {
          this.$toast('保存成功');
          // localStorage.removeItem('customerUser')
          // localStorage.removeItem('customerProductList')
          // setTimeout(e =>{
          //   this.model = {};
          //   this.productList = [];
          //   this.editState = false;
          //   this.checkedList = [];
          //   this.productNameList =[];
          //   this.checkAllState = false;
          // },2000)
				}else{
          this.$toast(res.Msg)

        }
			})
    }
  }
}
</script>

<style lang="scss" scoped>
.van-uploader {
  /deep/ .van-uploader__upload,
  /deep/ .van-uploader__preview {
    margin: 0;
  }
}
.advertPictures {
  /deep/ .van-uploader__upload,
  /deep/ .van-uploader__preview {
    margin-right: 10px;
    margin-bottom: 10px;
  }
}
.color-white {
	/deep/.van-icon {
		color: #fff;
	}

	/deep/.van-nav-bar__title {
		color: #fff;
	}
}
.wrapperbg{
  height: 194px;
  border-radius: 0% 0% 35% 35%;
}
.wrapper{
  padding:0 24px 24px 24px;
  margin-top: -170px;
}
.ontitle{
  color: #333;
  font-weight: bold;
  padding: 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.addproduct{
  font-size: 24px;
  width: 160px;
  height: 50px;
  line-height: 50px;
  border-radius: 25px;
  border: 2px solid #333333;
  font-weight: normal;
  display: flex;
  justify-content: center;
  align-content: center;
}
.color3{
  color: #333;
  margin-top: 10px;
  margin-right: 3px;
  font-weight: bold;
}
/deep/.van-checkbox{
		margin-bottom: 0 !important;
	}
  [data-theme='blue'] .checked:before {
    background-color: #F1270C!important;
    border-color: #F1270C!important;
  }
	.checkbox{
		padding-left: 50px;
		padding-right: 35px;
		&:before{
			left: 0px;
		}
		&:after{
			left: 12px;
		}
	}
  .one-del{
    width: 120px;
    height: 48px;
    border-radius: 28px;
    border: 1px solid #F1270C;
    font-size: 24px;
    line-height: 48px;
    text-align: center;
  }
  .submitBtn{
    color: #666;
  }
  .numinput{
    width: 146px;
    height: 56px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid #999;
    font-size: 28px;
    color: #333;
    font-weight: bold;
  }
  .numinput1{
    width: 96px;
    text-align: right;
  }
  .bt-button{
    width: 750px;
    height: 120px;
    background: #FFFFFF;
    box-shadow: 0px -2px 10px 0px rgba(0,0,0,0.1);
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 100;
  }
  .bor-ra{
    height: 88px;
    // background: #F1270C;
    border-radius: 44px;
    margin-top: 15px;
    margin:15px 15px 0 15px;
    border: 0 none;

  }
  .bor-ra1{
    height: 88px;
    border-radius: 44px;
    margin-top: 15px;
    margin:15px 15px 0 15px;
    background: #fff;
  }
  .gradeList{
    display: flex;
    flex-flow: wrap;
    &>div{
      width: auto;
      padding: 0 10px;
      height: 56px;
      line-height: 56px;
      text-align: center;
      background: #F4F4F4;
      border-radius: 8px;
      margin-right: 12px;
      margin-bottom: 12px;
      border: 1px solid #F4F4F4;
    }
    &>div.active{
      background: #FFFFFF;
      color: #F1270C;
      border-color:#F1270C;

    }
  }
  .register-form{
  }
  .addressDiv{
    background: #F4F5F6;
    padding: 30px 24px;
    display: flex;
    align-items: center;
    margin: 24px 24px 0 24px;
    .mapicon{
      width: 48px;
      height: 48px;
      margin-right: 12px;
    }
  }
  .righticon{
    position: absolute;
    right: 24px;
  }
  .btn-input-box:before {
    content: '';
    opacity: 0;
}
.amouninput{
  width: 464px;
  height: 96px;
  background: #F0F0F0;
  border-radius: 48px;
  text-align: center;
  margin: 0 auto;
}
.inputmax{
  min-width: 90px;
  justify-content: center;
}
</style>
